package com.codedancer.campus.mapper;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.codedancer.campus.common.core.BaseMapper;
import com.codedancer.campus.po.CommentReport;
import com.codedancer.campus.qo.commentReport.CommentReportPageSearchQo;

public interface CommentReportMapper extends BaseMapper<CommentReport> {

  /**
   * 分页查询评论举报
   *
   * @param commentReportPage
   * @param commentReportPageSearchQo
   * @return
   */
  default IPage<CommentReport> page(Page<CommentReport> commentReportPage,
      CommentReportPageSearchQo commentReportPageSearchQo) {
    LambdaQueryWrapper<CommentReport> lambdaQueryWrapper = new LambdaQueryWrapper<>();
    if (ObjectUtil.isNotEmpty(commentReportPageSearchQo.getCommentReportTypeUuid())) {
      lambdaQueryWrapper.eq(CommentReport::getCommentReportTypeUuid,
          commentReportPageSearchQo.getCommentReportTypeUuid());
    }
    return selectPage(commentReportPage, lambdaQueryWrapper);
  }

  /**
   * 根据评论举报类型判断是否存在评论举报
   *
   * @param uuid
   * @return
   */
  default boolean existsByCommentReportTypeUuid(String uuid) {
    LambdaQueryWrapper<CommentReport> lambdaQueryWrapper = new LambdaQueryWrapper<>();
    lambdaQueryWrapper.eq(CommentReport::getCommentReportTypeUuid, uuid);
    return selectCount(lambdaQueryWrapper) > 0;
  }
}
